const Pk = {
  state: {
    status: "matching",//状态
    socket: null,
    opponentName: "",//对手名字
    opponentPhoto: "https://cdn.acwing.com/media/article/image/2022/08/09/1_1db2488f17-anonymous.png",
    map: "",
    aid: 0,//保存双方信息
    asx: 0,
    axy: 0,
    bid: 0,
    bsx: 0,
    bsy: 0,
    gameObject: null,
    loser: "",//id
    directionShow: "无",
    lastTime: "5",
    timer: null,
    winScore: "",
    loseScore: "",
  },
  getters: {
  },
  mutations: {
    updatePK(state, socket) {
      state.socket = socket;
    },
    updateOpponent(state, opponent) {
      state.opponentName = opponent.name;
      state.opponentPhoto = opponent.photo;
    },
    updateStatus(state, status) {
      state.status = status;
    },
    updateMap(state, map) {//更新game信息
      state.map = map;
    },
    updateGame(state, gameInfo) {
      state.status = "gaming";
      state.map = gameInfo.map;
      state.aid = gameInfo.aid;
      state.asx = gameInfo.asx;
      state.asy = gameInfo.asy;
      state.bid = gameInfo.bid;
      state.bsx = gameInfo.bsx;
      state.bsy = gameInfo.bsy;
    },
    updateGameObject(state, gameObject) {
      state.gameObject = gameObject;
    },
    loserSet(state, loser) {
      if (loser == "all") {
        state.loser = "all";
        state.winScore = 0;
        state.loseScore = 0;
      }
      else state.loser = loser;

      if (state.loser == "1") state.loser = state.aid;
      else if (state.loser == "2") state.loser = state.bid;
    },
    updateDirectionShow(state, fangxiang) {//上面那个指示方向的
      state.directionShow = fangxiang;
    },
    updateLastTime() {

    },
    startTime(state) {
      state.lastTime = "5";
      clearInterval(state.timer);
      state.timer = setInterval(() => {
        if (state.lastTime != 0)
          state.lastTime--;
      }, 1000)
    },
    updateScore(state, data) {
      state.winScore = data.winScore;
      state.loseScore = data.loseScore;
    },
    closeSocket(state) {
      state.socket.onclose();
    },
    clear(state) {
      state.status = "matching";
      //state.socket = null;
      state.opponentName = "";//对手名字
      state.opponentPhoto = "https://cdn.acwing.com/media/article/image/2022/08/09/1_1db2488f17-anonymous.png";
      state.map = "";
      state.aid = 0;//保存双方信息
      state.asx = 0;
      state.axy = 0;
      state.bid = 0;
      state.bsx = 0;
      state.bsy = 0;
      state.gameObject = null;
      state.loser = "";//id
      state.directionShow = "无";
      state.lastTime = "5";
      clearInterval(state.timer);
    }
  },
  actions: {
  },
  modules: {

  }
};
export default Pk;
